<script setup>
import { getOrderAPI } from '@/apis/pay'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { useCountDown } from '@/composables/useCountDown'
const { formatTime, start } = useCountDown()

// 获取订单数据
const route = useRoute()
const payInfo = ref({})
const getPayInfo = async () => {
  const res = await getOrderAPI(route.query.id)
  payInfo.value = res.result
  // 初始化倒计时秒数
  start(res.result.countdown)
}
onMounted(() => getPayInfo()) 
// 跳转支付
// 携带订单id以及回调地址跳转到支付地址（get）
// 支付地址
const baseURL = 'http://pcapi-xiaotuxian-front-devtest.itheima.net/'
const backURL = 'http://127.0.0.1:5173/paycallback'
const redirectUrl = encodeURIComponent(backURL)
const payUrl = `${baseURL}pay/aliPay?orderId=${route.query.id}&redirect=${redirectUrl}`
</script>


<template>
  <div class="xtx-pay-page">
    <div class="container">
      <!-- 付款信息 -->
      <div class="pay-info">
        <span class="icon iconfont icon-queren2"></span>
        <div class="tip">
          <p>订单提交成功！请尽快完成支付。</p>
          <p>支付还剩 <span>{{ formatTime }}</span>, 超时后将取消订单</p>
        </div>
        <div class="amount">
          <span>应付总额：</span>
          <span>¥{{ payInfo.payMoney?.toFixed(2) }}</span>
        </div>
      </div>
      <!-- 付款方式 -->
      <div class="pay-type">
        <p class="head">选择以下支付方式付款</p>
        <div class="item">
          <p>支付平台</p>
          <a class="btn wx" href="javascript:;"></a>
          <a class="btn alipay" :href="payUrl">支付宝</a>
        </div>
        <div class="item">
          <p>支付方式</p>
          <a class="btn alipay" :href="payUrl">支付宝(推荐)</a>
          <a class="btn" href="javascript:;">招商银行</a>
          <a class="btn" href="javascript:;">工商银行</a>
          <a class="btn" href="javascript:;">建设银行</a>
          <a class="btn" href="javascript:;">农业银行</a>
          <a class="btn" href="javascript:;">交通银行</a>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang='scss'>
.pay-info{
  width: 100%;
  height: 200px;
  background-color: #fff;
  margin: 20px auto;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding-left: 100px;

  .icon{
    width: 60px;
    margin-right: 10px;
    font-size: 60px;
    color: $xtxColor;
  }
  .tip{
    flex: 5;
    p{
      &:first-child{
        font-size: 24px;
      }
      &:last-child{
        font-size: 16px;
      }
    }
  }
  .amount{
    flex: 2;

    span{
      &:first-child{
        color: $xtxColor
      }
      &:last-child{
        color: $helpColor
      }
      span{
        color: $priceColor;
      }
    }
  }
}
.pay-type{
  width: 100%;
  height: 500px;
  background-color: #fff;
  .head{
    line-height: 49px;
    height: 50px;
    border-bottom: 1px solid #eee;
    padding-left: 20px;
  }
  .item{
    padding-left: 20px;
    padding-top: 20px;
    &:first-child{
      margin-top: 20px;
      p{
        font-size: 14px;
        font-weight: bold;
      }
    }
    &:last-child{
      margin-top: 20px;
      p{
        width: 100%;
        font-size: 14px;
        font-weight: bold;
      }
      a.btn{
        display: inline-block;
        width: 120px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        border: 1px solid #eee;
        margin: 20px 20px 0 0;
      }
    }
  }
}
</style>